#include "gndmessage.h"
#include <gtk/gtk.h>
#include <stdio.h>
#include <string.h>

void test_from_bin();

int main(int argc, char ** argv)
{
    test_from_bin();
    return 0;
}


void test_from_bin()
{
    gchar * data1 = "abcdefg";
    gchar * data2 = "你好你好";
    gchar * data3 = "123456789";
    g_print(data2);
    g_print("你好你好");
    printf(data2);
    printf("你好你好");
    GndMessage * message = gnd_message_new();
    gnd_message_add_raw_data(message, data1, strlen(data1) + 1);
    gnd_message_add_raw_data(message, data2, strlen(data2) + 1);
    gnd_message_add_raw_data(message, data3, strlen(data3) + 1);
    gchar * result_data = NULL;
    gint all_data_len = 0;
    all_data_len = gnd_message_generate_bin(message, &result_data);

    if (!result_data || !all_data_len) {
        g_print("failure : no bin\n");
        return;
    }

    gnd_message_free(message);
    message = gnd_message_new_with_data(result_data, all_data_len);

    if (!message) {
        g_print("failure : message new failure\n");
        return;
    }

    for (int t = 0;
         t < g_queue_get_length(message->message_data_list);
         t ++) {
        GndMessageData * t_data = (GndMessageData *) g_queue_peek_nth(message->message_data_list, t);
        g_print("\nsection %d; len %d\ndata :\n", t, t_data->len);
        g_print(t_data->data);
    }

    g_print("\nsucceed\n");
    return;
}
